Skip to content

Support socket activation for mdbook serve#3093

Open
Ericson2314 wants to merge 1 commit intorust-lang:masterfrom
Ericson2314:socket-activation
Open

Support socket activation for mdbook serve#3093
Ericson2314 wants to merge 1 commit intorust-lang:masterfrom
Ericson2314:socket-activation

Conversation

@Ericson2314
Copy link
Copy Markdown

Add a --socket-activate flag that adopts a pre-bound TCP listener from LISTEN_FDS instead of binding a new one. This allows process managers like foreman (with Socketfile support) or systemd to own the socket, so it survives server restarts.

Three modes:

  • --socket-activate: require a passed-in socket, fail if absent
  • --port N / --hostname H: always bind, ignore LISTEN_FDS
  • Neither: try LISTEN_FDS first, fall back to binding the default

The listener is now bound in the main thread before spawning the server, so the actual address is always known for logging and --open.

Also parse --port as u16 at arg-parse time instead of leaving it as a string.

Socket activation is normally associated with systemd. And indeed, it would be peculiar to wire up this development command with systemd, but it is also used in other contexts more appropriate to this command, like https://github.com/mitsuhiko/systemfd, a development tool. From a Capsicum/WASI perspective, it also is generally better when tools can consume resources provided by a more privileged caller, rather than having to open them themselves. For these reasons, I think everything should support socket-activation.

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label May 7, 2026
@Ericson2314 Ericson2314 force-pushed the socket-activation branch from a8da753 to 67b5b46 Compare May 7, 2026 18:40
Add a `--socket-activate` flag that adopts a pre-bound TCP listener
from `LISTEN_FDS` instead of binding a new one. This allows process
managers like foreman (with Socketfile support) or systemd to own the
socket, so it survives server restarts.

Three modes:
- `--socket-activate`: require a passed-in socket, fail if absent
- `--port N` / `--hostname H`: always bind, ignore `LISTEN_FDS`
- Neither: try `LISTEN_FDS` first, fall back to binding the default

The listener is now bound in the main thread before spawning the
server, so the actual address is always known for logging and
`--open`.

Also parse `--port` as `u16` at arg-parse time instead of leaving
it as a string.

Socket activation is normally associated with systemd. And indeed, it
would be peculiar to wire up this development command with systemd, but
it is also used in other contexts more appropriate to this command, like
https://github.com/mitsuhiko/systemfd, a development tool. From a
Capsicum/WASI perspective, it also is generally better when tools can
consume resources provided by a more privileged caller, rather than
having to open them themselves. For these reasons, I think everything
should support socket-activation.
@Ericson2314 Ericson2314 force-pushed the socket-activation branch from 67b5b46 to a25052e Compare May 7, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: waiting on a review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants